﻿@using ECG.Common
@using ECG.Utility
@using ECG.WebUI.CustomHelpers
@model List<ECG.Common.ProductByCateTopListPagingDto>
@if (Model.Any() && Model.Count > 2)
{
    <div class="cusBought">
        <div class="cusBought-header">
            <h2>Những sản phẩm khách hàng thường xuyên mua cùng</h2>
            <span class="cusBoughtPagging">Page 1 of 14</span>
        </div>
        <ul class="listTogether ul clearfix">
            @{
                decimal totalPrice = 0;
                decimal price = 0;
                var itemFirst = (ProductByCateTopListPagingDto) Model[0];
                if (itemFirst.PromotionPrice > 0)
                {
                    totalPrice += itemFirst.PromotionPrice;
                    price = itemFirst.PromotionPrice;
                }
                else
                {
                    totalPrice += itemFirst.Price;
                    price = itemFirst.Price;
                }
            }
            <li imap="@itemFirst.Id">
                <img src="@string.Format("{0}", itemFirst.ImagePath.ImagePathThumb(75, 75))" width="75" height="75" alt="">
            </li>
            <li class="to-plus">+</li>
            @for (int i = 1; i < Model.Count; i++)
            {
                var item = (ProductByCateTopListPagingDto)Model[i];
                var pLink = Url.Action("Index", "ProductDetail", new { productName = StringUtil.RemoveSpecialCharactersVn(item.Name), productId = item.Id });
                <li imap="@item.Id">
                    <a href="@pLink">
                        <img src="@string.Format("{0}", item.ImagePath.ImagePathThumb(75, 75))" width="75" height="75" alt="@item.Name">
                    </a>
                </li>
                if (i != Model.Count - 1)
                {
                <li class="to-plus">+</li>
                }

                if (item.PromotionPrice > 0)
                {
                    totalPrice += item.PromotionPrice;
                }
                else
                {
                    totalPrice += item.Price;
                }


            }
            <li style="padding-top: 15px; padding-left: 15px;" class="plcbtnorder">
                <p class="together-txt">
                    Giá tiền cho @Model.Count sản phẩm này: <span class="together-prce total-price" iprice="@totalPrice">@totalPrice.ToString("#,###") đ</span>
                </p>
                <div>
                    <input type="submit" class="btnTogetherBuyAll" value="Đặt mua tất cả">
                </div>
            </li>
        </ul>
        <div class="together-check">
            <div class="together-item-chk chkTogether">
                <input type="checkbox" name="together" checked="checked" imap="@itemFirst.Id" class="to_x_cs">
                <span><strong>Sản phẩm hiện tại:</strong> @itemFirst.Name </span>
                @if (!string.IsNullOrEmpty(itemFirst.ProviderName))
                {
                    <span class="to-provi">- @itemFirst.ProviderName</span>
                }
                <span class="together-prce" iprice="@price">@price.ToString("#,###") đ</span>
            </div>
            @for (int i = 1; i < Model.Count; i++)
            {
                var item = (ProductByCateTopListPagingDto)Model[i];
                var pLink = Url.Action("Index", "ProductDetail", new { productName = StringUtil.RemoveSpecialCharactersVn(item.Name), productId = item.Id });
                decimal itemPrice = 0;
                <div class="together-item-chk">
                    @{
                        var css = "";
                        css = i == Model.Count - 1 ? "to_z_cs" : "";
                    }
                    <input type="checkbox" name="together" checked="checked" imap="@item.Id" class="@css">
                    <span>
                        <a href="@pLink">@item.Name </a>
                    </span>

                    @if (!string.IsNullOrEmpty(item.ProviderName))
                    {
                        <span class="to-provi">- <a href="@Url.Action("Index","ProductByProvider",new {Provider = item.Id,item.ProviderName  })">@item.ProviderName</a></span>
                    }

                    @{
                        itemPrice = item.PromotionPrice > 0 ? item.PromotionPrice : item.Price;
                    }
                    <span class="together-prce" iprice="@itemPrice">@itemPrice.ToString("#,###") đ</span>
                </div>
            }
        </div>
    </div>
}
